"use strict";
cc._RF.push(module, '33fa5y6f7tIKYZAesvgZncO', 'level_peopleArchery');
// scripts/levelBundles/level_PeopleArchery/level_peopleArchery.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var LevelBase_1 = require("../../Game/Base/LevelBase");
var gameEngine_1 = require("../../engines/gameEngine");
var CsvFileKind_1 = require("../../engines/libs/CsvFileKind");
var data_control_1 = require("../../engines/libs/data_control");
var level_PeopleArcheryUnitBase_1 = require("./base/level_PeopleArcheryUnitBase");
var level_peopleArcheryOption_1 = require("./unit/level_peopleArcheryOption");
var level_peopleArcheryPeople_1 = require("./unit/level_peopleArcheryPeople");
var level_peopleArcheryEnemy_1 = require("./unit/level_peopleArcheryEnemy");
var level_peopleArcheryBox_1 = require("./unit/level_peopleArcheryBox");
var level_peopleArchery_openBoxPage_1 = require("./page/level_peopleArchery_openBoxPage");
var level_peopleArcheryBullet_1 = require("./unit/level_peopleArcheryBullet");
var MainRoot_1 = require("../../Game/MainRoot");
var Enum_1 = require("../../Game/Enum");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_peopleArchery = /** @class */ (function (_super) {
    __extends(level_peopleArchery, _super);
    function level_peopleArchery() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        /**角色content */
        _this.unitContent = null;
        /**角色预制体 */
        _this.peopleP = null;
        /**箭预制体 */
        _this.arrowP = null;
        /**敌方预制体 */
        _this.enemyP = null;
        /**选项预制体 */
        _this.optionP = null;
        _this.boxPrefab = null;
        _this.openBoxPagePrefab = null;
        _this.resultP = null;
        _this.btnStart = null;
        _this.subP = null;
        _this.touchNode = null;
        _this.testFlag = false;
        _this.lbParam = null;
        /**角色左右移动的最小X坐标 */
        _this.peopleMinX = -150;
        /**角色左右移动的最大X坐标 */
        _this.peopleMaxX = 150;
        /**子弹节点池 */
        _this.bulletPool = new cc.NodePool();
        /**游戏是否暂停 */
        _this.gamePauseFlag = true;
        /**关卡数据 */
        _this.peopleArcheryData = null;
        /**当前地图移动的总距离 */
        _this.moveDis = 0;
        /**当前波次移动的距离 */
        _this.waveDis = 0;
        /**当前波次 */
        _this.realWave = 3;
        /**游戏时间 */
        _this.gameTime = 0;
        /**造成的伤害 */
        _this.damage = 0;
        /**杀敌数 */
        _this.killCount = 0;
        /**当前波次 */
        _this.curWave = 0;
        /**最大波次 */
        _this.maxWave = 0;
        _this.allWaves = [];
        _this.firstFlag = true;
        /**当前角色 */
        _this.role = null;
        _this.infinityFlag = false;
        _this.infinityHpData = null;
        _this.roleData = null;
        _this.curMoney = 0;
        _this.inGamePage = null;
        return _this;
    }
    level_peopleArchery.prototype.Init = function (info) {
        return __awaiter(this, void 0, Promise, function () {
            var inGamePrams, page;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.levelInfo = info;
                        this.m_mode = info.mode;
                        this.tips = info.tips;
                        inGamePrams = {
                            mode: this.m_mode,
                            levelInfo: this.levelInfo,
                            title: info.title,
                            tips: info.tips,
                            hideTitle: info.hideTitle
                        };
                        this.infinityFlag = this.levelInfo["infinityFlag"];
                        this.infinityHpData = gameEngine_1.default.getManagers().csvDataManager.getCsvData(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryInfinityEnemyHp);
                        gameEngine_1.default.getManagers().soundMgr.loadSoundBundle("peopleArcherySound");
                        this.roleData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryRole, gameEngine_1.default.getManagers().peopleArcheryManager.getData().curUseRoleId);
                        return [4 /*yield*/, this.initLevel()];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.PEOPLE_ARCHERY_INGAME_PAGE, inGamePrams)];
                    case 2:
                        page = _a.sent();
                        page.bindLevel(this);
                        this.inGamePage = page;
                        return [2 /*return*/];
                }
            });
        });
    };
    level_peopleArchery.prototype.start = function () {
        if (gameEngine_1.default.getServices().ossSrv.getPlatform() == "tt") {
            this.testFlag = false;
        }
    };
    level_peopleArchery.prototype.initLevel = function () {
        return __awaiter(this, void 0, void 0, function () {
            var ids, _i, ids_1, i, waveData, enemyType, bossPro, bigPro, middle_pro;
            return __generator(this, function (_a) {
                this.peopleArcheryData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryTimeLine, this.levelInfo.level);
                ids = gameEngine_1.default.getManagers().csvDataManager.getCsvIds(CsvFileKind_1.CsvFileKind.CsvFile[this.peopleArcheryData["timeLineFileName"]]);
                for (_i = 0, ids_1 = ids; _i < ids_1.length; _i++) {
                    i = ids_1[_i];
                    waveData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile[this.peopleArcheryData["timeLineFileName"]], i);
                    enemyType = -1;
                    bossPro = Number(waveData["boss_pro"]);
                    bigPro = Number(waveData["big_pro"]);
                    middle_pro = Number(waveData["middle_pro"]);
                    enemyType = Math.random() < bossPro ? 0 : enemyType;
                    if (enemyType != 0) {
                        if (Math.random() < bigPro) {
                            enemyType = 1;
                        }
                        else if (Math.random() < middle_pro) {
                            enemyType = 2;
                            this.maxWave++;
                        }
                        else {
                            enemyType = 3;
                            this.maxWave++;
                        }
                    }
                    this.allWaves.push(enemyType);
                }
                this.moveDis = -Number(this.peopleArcheryData["start_dis"]);
                this.curMoney = Number(this.peopleArcheryData["complete_money"]);
                this.curWave = 0;
                this.addRole(1);
                this.createStartWave();
                return [2 /*return*/];
            });
        });
    };
    /**移动 */
    level_peopleArchery.prototype.onTouchMoveRoleNode = function (e) {
        if (this.gamePauseFlag) {
            return;
        }
        var delta = e.getDelta();
        var dx = delta.x;
        var px = this.role.node.x;
        if (px + dx > this.peopleMaxX) {
            dx = this.peopleMaxX - px;
        }
        else if (px + dx < this.peopleMinX) {
            dx = this.peopleMinX - px;
        }
        this.role.node.x += dx;
    };
    /**
     * 加载指定数量的角色
     * @param roleCount 需要加载的角色数量
     */
    level_peopleArchery.prototype.addRole = function (roleCount) {
        for (var i = 0; i < roleCount; i++) {
            var role = cc.instantiate(this.peopleP);
            var rs = role.getComponent(level_peopleArcheryPeople_1.default);
            this.role = rs;
            this.initRoleData(role);
            this.oneUnitBindLevel(rs);
            role.setParent(this.unitContent);
            role.setPosition(0, 300);
            this.touchNode.on('touchmove', this.onTouchMoveRoleNode, this);
        }
    };
    level_peopleArchery.prototype.initRoleData = function (role) {
        var fileName = this.roleData["role_file"];
        var level = gameEngine_1.default.getManagers().peopleArcheryManager.getRoleData(this.roleData.role_id).level;
        var data = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem("config/csv/peopleArchery/role/" + fileName, level);
        console.log("角色数据：", data);
        var rs = role.getComponent(level_peopleArcheryPeople_1.default);
        rs.minArrowDis = Number(this.peopleArcheryData["min_arrowDis"]);
        rs.maxArrowDis = Number(this.peopleArcheryData["max_arrowDis"]);
        rs.minAtkSpd = Number(this.peopleArcheryData["min_atk_spd"]);
        rs.maxAtkSpd = Number(this.peopleArcheryData["max_atk_spd"]);
        rs.minAtk = Number(this.peopleArcheryData["min_atk"]);
        rs.maxHp = Number(data["hp"]);
        rs.hp = Number(data["hp"]);
        rs.atk = Number(data["atk"]); // + O1HD.getManagers().peopleArcheryManager.getData().atkAddition;
        rs.atkSpd = Number(this.peopleArcheryData["initAtkSpd"]);
        rs.moveSpd = Number(this.peopleArcheryData["initMoveSpd"]);
        rs.arrowDis = Number(this.peopleArcheryData["initArrowDis"]);
        rs.bulletNum = Number(this.peopleArcheryData["init_arrowNum"]);
        rs.atkAddition = Number(this.peopleArcheryData["atk_addition"]);
        rs.strikeRecover = Number(this.peopleArcheryData["strike_recover"]);
        rs.hpBenefit = Number(this.peopleArcheryData["hp_benefit"]);
        rs.revitAlize = Number(this.peopleArcheryData["revit_alize"]); // + O1HD.getManagers().peopleArcheryManager.getData().revitAlize;
        var active_Talent = data["active_Talent"];
        var activeTalent = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryTalent, active_Talent);
        var activeFile = activeTalent["talent_file"];
        var activeData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem("config/csv/peopleArchery/talent/" + activeFile, level);
        // 激活主动技能
        var activeTypes = activeData["param_type"].split("|");
        var activeParams = activeData["param_num"].split("|");
        for (var i = 0; i < activeTypes.length; i++) {
            var data_1 = { param_type: activeTypes[i], option_param: activeParams[i] };
            this.parseDataAddPeople(data_1);
        }
        //激活被动技能
        var peoples = gameEngine_1.default.getManagers().peopleArcheryManager.getData().unlockRole;
        for (var _i = 0, peoples_1 = peoples; _i < peoples_1.length; _i++) {
            var people = peoples_1[_i];
            var pId = people.id;
            var pLevel = people.level;
            var roleData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryRole, pId);
            var rFileName = roleData["role_file"];
            var rData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem("config/csv/peopleArchery/role/" + rFileName, level);
            var passive_Talent = rData["passive_Talent"];
            var passiveTalent = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryTalent, passive_Talent);
            var passiveFile = passiveTalent["talent_file"];
            var passiveData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem("config/csv/peopleArchery/talent/" + passiveFile, pLevel);
            var passiveTypes = passiveData["param_type"].split("|");
            var passiveParams = passiveData["param_num"].split("|");
            for (var i = 0; i < passiveTypes.length; i++) {
                var data_2 = { param_type: passiveTypes[i], option_param: passiveParams[i] };
                this.parseDataAddPeople(data_2);
            }
        }
        //测试数据
        // rs.criticalPro = 0.5;
        // rs.criticalAddition = 1.5;
        // rs.shotLeech = 0.2;
        // rs.maxHpAddition = 0.2;
        // rs.revitalizeAddition = 0.2;
        // rs.reduceDamage = 0.2;
        // rs.bossHpReduce = 0.2;
        // rs.revitalizePercent = 0.2;
        // rs.bossDeathRevitalizePercent = 0.2;
    };
    level_peopleArchery.prototype.oneUnitBindLevel = function (unit) {
        unit.bindLevel(this);
    };
    /**获取一个子弹节点 */
    level_peopleArchery.prototype.getOneBullet = function () {
        var bullet = null;
        if (this.bulletPool.size() > 0) {
            bullet = this.bulletPool.get();
        }
        else {
            bullet = cc.instantiate(this.arrowP);
        }
        return bullet;
    };
    level_peopleArchery.prototype.update = function (dt) {
        if (this.testFlag && this.role) {
            this.lbParam.string = "\n            \u6700\u5927\u8840\u91CF\uFF1A" + this.role.maxHp + "\n            \u8840\u91CF\uFF1A" + this.role.hp + "\n            \u653B\u901F\uFF1A" + this.role.atkSpd + "\n            \u653B\u51FB\u529B\uFF1A" + this.role.atk + "\n            \u6C38\u4E45\u653B\u51FB\uFF1A" + gameEngine_1.default.getManagers().peopleArcheryManager.getData().atkAddition + "\n            \u649E\u51FB\u56DE\u590D\uFF1A" + this.role.strikeRecover + "\n            \u8840\u91CF\u6536\u76CA\uFF1A" + this.role.hpBenefit + "\n            \u6BCF\u4E24\u79D2\u56DE\u8840\uFF1A" + this.role.revitAlize + "\n            \u653B\u51FB\u52A0\u6210\uFF1A" + this.role.atkAddition + "\n            \u4F24\u5BB3\u51CF\u514D\uFF1A " + this.role.reduceDamage + "\n            \u66B4\u51FB\u7387\uFF1A" + this.role.criticalPro + "\n            \u66B4\u51FB\u4F24\u5BB3\uFF1A" + this.role.criticalAddition + "\n            \u8840\u91CF\u4E0A\u9650\uFF1A" + this.role.maxHpAddition + "\n            \u56DE\u8840\u589E\u5F3A\uFF1A" + this.role.revitalizeAddition + "\n            boss\u8840\u91CF\u964D\u4F4E\uFF1A" + this.role.bossHpReduce + "\n            \u6BCF\u4E94\u79D2\u56DE\u590D\u8840\u91CF\uFF1A" + this.role.revitalizePercent + "\n            \u5C04\u51FB\u5438\u8840\uFF1A" + this.role.shotLeech + "\n            \u91D1\u5E01\u52A0\u6210\uFF1A" + this.role.goldAddition + "\n            \u51FB\u8D25boss\u56DE\u8840\uFF1A" + this.role.bossDeathRevitalizePercent + "\n            ";
        }
        if (this.gamePauseFlag) {
            return;
        }
        var moveSpeed = this.getRoleMoveSpd();
        var moveDis = moveSpeed * dt;
        this.moveDis += moveDis;
        this.waveDis += moveDis;
        this.gameTime += dt;
        if (this.waveDis >= this.peopleArcheryData["oneWaveDis"]) {
            this.waveDis = 0;
            // 创建一波
            this.createOneWave(this.realWave);
            this.realWave++;
        }
    };
    //创建开始波次
    level_peopleArchery.prototype.createStartWave = function () {
        for (var i = 0; i < this.realWave; i++) {
            this.createOneWave(i);
        }
    };
    level_peopleArchery.prototype.createOneWave = function (waveIndex) {
        var ids = gameEngine_1.default.getManagers().csvDataManager.getCsvIds(CsvFileKind_1.CsvFileKind.CsvFile[this.peopleArcheryData["timeLineFileName"]]);
        if (this.realWave >= ids.length) {
            return;
        }
        var lastWaveFlag = false;
        if (this.realWave == ids.length - 1) {
            lastWaveFlag = true;
        }
        var waveData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile[this.peopleArcheryData["timeLineFileName"]], waveIndex + 1);
        var waveInterval = Number(this.peopleArcheryData["oneWaveDis"]);
        var maxY = (waveIndex + 1) * waveInterval;
        var minY = maxY - waveInterval;
        var addY = minY - this.moveDis;
        var posAry = data_control_1.default.randomSortArray([cc.v2(this.peopleMinX, waveInterval * 0.4), cc.v2(this.peopleMaxX, waveInterval * 0.4), cc.v2(this.peopleMinX, waveInterval * 0.6), cc.v2(this.peopleMaxX, waveInterval * 0.6)]);
        var posCopy = [];
        var enemyNum = Number(waveData["enemy_num"]);
        var num = Math.random() < enemyNum % 1 ? 1 : 0;
        var realNum = Math.floor(enemyNum) + num;
        var hasOption = true;
        var enemyType = -1;
        var enemyHp = Number(waveData["wave_hp"]);
        if (this.infinityFlag) {
            var infinityWaveData = Number(this.infinityHpData[waveIndex + 1][this.infinityHpData["title"]["enemyHp_" + gameEngine_1.default.getManagers().peopleArcheryManager.getData().curInfinityLevel]]);
            enemyHp = Number(infinityWaveData);
        }
        var hpRatio = 0;
        var boss_hp_reduce = 0;
        enemyType = this.allWaves[waveIndex];
        switch (enemyType) {
            case 0: {
                posAry = data_control_1.default.randomSortArray([cc.v2(0, waveInterval)]);
                realNum = 1;
                hasOption = false;
                hpRatio = Number(this.peopleArcheryData["boss_hp_ratio"]);
                boss_hp_reduce = this.role.bossHpReduce;
                break;
            }
            case 1: {
                hasOption = false;
                posAry = data_control_1.default.randomSortArray([cc.v2(0, waveInterval)]);
                hpRatio = Number(this.peopleArcheryData["big_hp_ratio"]);
                boss_hp_reduce = this.role.bossHpReduce;
                break;
            }
            case 2: {
                hpRatio = Number(this.peopleArcheryData["middle_hp_ratio"]);
                break;
            }
            case 3: {
                hpRatio = Number(this.peopleArcheryData["small_hp_ratio"]);
                break;
            }
        }
        posCopy = posAry.concat();
        for (var i = 0; i < realNum; i++) {
            if (posAry.length < 1) {
                posAry = posCopy.concat();
            }
            switch (enemyType) {
                case 2:
                case 3: {
                    var pro = waveData["middle_pro"];
                    if (Math.random() < pro) {
                        hpRatio = Number(this.peopleArcheryData["middle_hp_ratio"]);
                        enemyType = 2;
                    }
                    else {
                        hpRatio = Number(this.peopleArcheryData["small_hp_ratio"]);
                        enemyType = 3;
                    }
                    break;
                }
            }
            var pos = posAry.pop();
            pos.y += addY;
            var enemyNode = cc.instantiate(this.enemyP);
            var es = enemyNode.getComponent(level_peopleArcheryEnemy_1.default);
            this.oneUnitBindLevel(es);
            es.bindType(enemyType, lastWaveFlag, waveData);
            var hp = enemyHp * hpRatio;
            // if(enemyType == 0 || enemyType == 1){
            //     console.log(hp,"原有血量");
            // }
            hp -= hp * boss_hp_reduce;
            // if(enemyType == 0 || enemyType == 1){
            //     console.log(hp,"现有血量");
            // }
            es.maxHp = hp;
            es.hp = hp;
            enemyNode.setParent(this.unitContent);
            enemyNode.setPosition(pos);
        }
        if (hasOption) {
            var nowWaveOptionType = waveData["option_Type"];
            var optionNodes = [];
            var firstFlag = this.firstFlag;
            var roleProfile = this.role.profile;
            var createOptionsCount = roleProfile != "0" && nowWaveOptionType == "1" ? 1 : 2;
            var optionStr = waveData.arise_options;
            var optionWeightStr = waveData.arise_options_weight;
            var surviveCatastropheData = null;
            switch (nowWaveOptionType) {
                case "1": {
                    switch (roleProfile) {
                        case "1": {
                            optionStr = waveData.fairy_arise_options;
                            optionWeightStr = waveData.fairy_arise_weight;
                            break;
                        }
                        case "2": {
                            optionStr = waveData.magic_arise_options;
                            optionWeightStr = waveData.magic_arise_weight;
                            break;
                        }
                    }
                    break;
                }
                case "2": {
                    var surviveCatastropheIds = gameEngine_1.default.getManagers().csvDataManager.getCsvIds(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcherySurviveCatastrophe);
                    var randId = data_control_1.default.getRandItemOfArray(surviveCatastropheIds);
                    surviveCatastropheData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcherySurviveCatastrophe, randId);
                    break;
                }
            }
            var ariseOptions = [];
            var optionPos = [cc.v2(this.peopleMinX, maxY - this.moveDis), cc.v2(this.peopleMaxX, maxY - this.moveDis)]; //data_control.randomSortArray([cc.v2(this.peopleMinX,maxY - this.moveDis),cc.v2(this.peopleMaxX,maxY - this.moveDis)]);
            for (var i = 0; i < createOptionsCount; i++) {
                switch (nowWaveOptionType) {
                    case "1": {
                        if (this.role.profile == "0") {
                            if (i == 0) {
                                optionStr = waveData.fairy_arise_options;
                                optionWeightStr = waveData.fairy_arise_weight;
                            }
                            else {
                                optionStr = waveData.magic_arise_options;
                                optionWeightStr = waveData.magic_arise_weight;
                            }
                        }
                        break;
                    }
                    case "2": {
                        if (i == 0) {
                            optionStr = surviveCatastropheData.surviveCatastrophe_one_option;
                            optionWeightStr = surviveCatastropheData.surviveCatastrophe_one_option_weight;
                        }
                        else {
                            optionStr = surviveCatastropheData.surviveCatastrophe_two_option;
                            optionWeightStr = surviveCatastropheData.surviveCatastrophe_two_option_weight;
                        }
                        break;
                    }
                }
                var optionTypes = optionStr.split("|");
                var weightAry = optionWeightStr.split("|").map(function (value) {
                    var v = Number(value);
                    return v;
                });
                var weightIndex = data_control_1.default.getRandIPosByWeights(weightAry);
                var optionType = optionTypes[weightIndex];
                var optionData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryOptionDoor, optionType);
                var optionAry = optionData.option_door_arise_type.split("|");
                var randO = data_control_1.default.getRandItemOfArray(optionAry);
                var optionTypeAry = randO.split("&");
                if (optionAry.length >= 2) {
                    optionTypeAry = optionAry[i].split("&");
                }
                var randType = data_control_1.default.getRandItemOfArray(optionTypeAry);
                var optionsAry = this.getPeopleArcheryOptions(randType);
                var randData = data_control_1.default.getRandItemOfArray(optionsAry);
                while (ariseOptions.includes(randData["optionId"])) {
                    randType = data_control_1.default.getRandItemOfArray(optionTypeAry);
                    optionsAry = this.getPeopleArcheryOptions(randType);
                    randData = data_control_1.default.getRandItemOfArray(optionsAry);
                }
                var curOptionType = "0";
                switch (nowWaveOptionType) {
                    case "1": {
                        if (this.role.profile == "0") {
                            curOptionType = (i + 1).toString();
                            this.firstFlag = false;
                        }
                        else {
                            curOptionType = this.role.profile;
                            optionPos = [];
                            optionPos[0] = cc.v2(0, maxY - this.moveDis);
                        }
                        break;
                    }
                }
                ariseOptions.push(randData["optionId"]);
                var randPos = optionPos[i];
                var option = cc.instantiate(this.optionP);
                var optionScript = option.getComponent(level_peopleArcheryOption_1.default);
                this.oneUnitBindLevel(optionScript);
                optionScript.bindData(randData, lastWaveFlag, curOptionType, firstFlag, i, waveData, surviveCatastropheData);
                optionNodes.push(option);
                option.setPosition(randPos);
                option.setParent(this.unitContent);
            }
            for (var _i = 0, optionNodes_1 = optionNodes; _i < optionNodes_1.length; _i++) {
                var option = optionNodes_1[_i];
                var os = option.getComponent(level_peopleArcheryOption_1.default);
                os.groupOption = optionNodes;
            }
        }
    };
    level_peopleArchery.prototype.getOptions = function (optionStr, length) {
        var optionAry = optionStr.split("|");
        var ariseOptions = [];
        var options = [];
        for (var i = 0; i < length; i++) {
            var randType = data_control_1.default.getRandItemOfArray(optionAry);
            var optionsAry = this.getPeopleArcheryOptions(randType);
            var randData = data_control_1.default.getRandItemOfArray(optionsAry);
            while (ariseOptions.includes(randData["optionId"])) {
                randType = data_control_1.default.getRandItemOfArray(optionAry);
                optionsAry = this.getPeopleArcheryOptions(randType);
                randData = data_control_1.default.getRandItemOfArray(optionsAry);
            }
            ariseOptions.push(randData["optionId"]);
            options.push(randData);
        }
        return options;
    };
    /**
     *
     * @param type
     * @returns
     */
    level_peopleArchery.prototype.getPeopleArcheryOptions = function (type) {
        var ids = gameEngine_1.default.getManagers().csvDataManager.getCsvIds(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryOption);
        var datas = [];
        for (var _i = 0, ids_2 = ids; _i < ids_2.length; _i++) {
            var id = ids_2[_i];
            var data = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryOption, id);
            if (data.option_type == type) {
                datas.push(data);
            }
        }
        return datas;
    };
    /**
     * 解析数据并加到角色身上
     */
    level_peopleArchery.prototype.parseDataAddPeople = function (data) {
        var type = data === null || data === void 0 ? void 0 : data.param_type;
        var param = Number(data === null || data === void 0 ? void 0 : data.option_param);
        switch (type) {
            /**生命值 */
            case "0": {
                var hp = this.role.hp;
                var maxHp = this.role.realMaxHp;
                var hpAddition = param;
                var maxHpAddition = param;
                if (param > 0) {
                    hpAddition = Math.floor(param * this.role.hpBenefit);
                    maxHpAddition = Math.floor(param * this.role.hpBenefit);
                }
                var additionFlag = data["additionFlag"] == false ? false : true;
                if (data["reCoverMaxHp"] != "0") {
                    this.role.maxHp = maxHp + (additionFlag ? maxHpAddition : 0);
                }
                this.role.hp = hp + (additionFlag ? hpAddition : 0);
                if (param > 0) {
                    this.role.addHpAni();
                }
                if (this.role.hp <= 0) {
                    this.role.unitDeath();
                }
                if (data["reCoverMaxHp"] != "0") {
                    data.option_param = hpAddition.toString();
                    this.roleAddParamLb(data);
                }
                // console.log("初始血量：",hp,"最大血量：",this.role,maxHp,"血量加成：",hpAddition,"最大血量加成：",maxHpAddition);
                return;
                break;
            }
            /**攻击力 */
            case "1": {
                var atk = this.role.atk;
                this.role.atk = atk + param;
                break;
            }
            /**攻击速度 */
            case "2": {
                var atkSpd = this.role.initAtk;
                var addition = atkSpd * param;
                this.role.atkSpdAdd += addition;
                break;
            }
            /**箭的攻击距离 */
            case "3": {
                var arrowDis = this.role.arrowDis;
                this.role.arrowDis = arrowDis + param;
                break;
            }
            /**箭的数量 */
            case "4": {
                var arrowNum = this.role.bulletNum;
                this.role.bulletNum = arrowNum + param;
                break;
            }
            /**地图移动速度 */
            case "5": {
                var moveSpd = this.role.moveSpd;
                this.role.moveSpd = moveSpd + param;
                break;
            }
            /**永久攻击加成 */
            case "6": {
                gameEngine_1.default.getManagers().peopleArcheryManager.setData({ atkAddition: param }, true);
                var atk = this.role.atk;
                this.role.atk = atk + param;
                break;
            }
            /**每五秒回血 */
            case "7": {
                var revitAlize = this.role.revitAlize;
                this.role.revitAlize = revitAlize + param;
                break;
            }
            /**射击伤害加成 */
            case "8": {
                var atkAddition = this.role.atkAddition;
                this.role.atkAddition = atkAddition + param;
                break;
            }
            /**血量收益 */
            case "9": {
                var hpBenefit = this.role.hpBenefit;
                this.role.hpBenefit = hpBenefit + param;
                var hp = this.role.hp;
                var maxHp = this.role.maxHp;
                var hpAddition = hp / hpBenefit * this.role.hpBenefit; //this.role.hpBenefit * hp - hp * hpBenefit;
                var maxHpAddition = maxHp / hpBenefit * this.role.hpBenefit;
                this.role.maxHp = maxHpAddition;
                this.role.hp = hpAddition;
                break;
            }
            /**撞击回血 */
            case "10": {
                var strikeRecover = this.role.strikeRecover;
                this.role.strikeRecover = strikeRecover + param;
                break;
            }
            //永久回复
            case "11": {
                var revitAlize = this.role.revitAlize;
                this.role.revitAlize = revitAlize + param;
                gameEngine_1.default.getManagers().peopleArcheryManager.setData({ revitAlize: param }, true);
                break;
            }
            //伤害减免
            case "12": {
                var reduceDamage = this.role.reduceDamage;
                var reduceDamageAddition = reduceDamage + param;
                this.role.reduceDamage = reduceDamageAddition;
                break;
            }
            //射击暴击率
            case "13": {
                var criticalPro = this.role.criticalPro;
                var num = criticalPro + param;
                this.role.criticalPro = num;
                break;
            }
            //射击暴击伤害
            case "14": {
                var criticalAddition = this.role.criticalAddition;
                var num = criticalAddition + param;
                this.role.criticalAddition = num;
                break;
            }
            //血量上限加成
            case "15": {
                var maxHpAddition = this.role.maxHpAddition;
                var num = maxHpAddition + param;
                this.role.maxHpAddition = num;
                break;
            }
            //回血增强
            case "16": {
                var revitalizeAddition = this.role.revitalizeAddition;
                var num = revitalizeAddition + param;
                this.role.revitalizeAddition = num;
                break;
            }
            //boss血量降低
            case "17": {
                var bossHpReduce = this.role.bossHpReduce;
                var num = bossHpReduce + param;
                this.role.bossHpReduce = num;
                break;
            }
            //每五秒回复百分比血量
            case "18": {
                var revitalizePrecent = this.role.revitalizePercent;
                var num = revitalizePrecent + param;
                this.role.revitalizePercent = num;
                break;
            }
            //射击吸血
            case "19": {
                var shotLeech = this.role.shotLeech;
                var num = shotLeech + param;
                this.role.shotLeech = num;
                break;
            }
            //金币加成
            case "20": {
                var addition = this.role.goldAddition;
                var num = addition + param;
                this.role.goldAddition = num;
                break;
            }
            //boss死亡回复百分比血量
            case "21": {
                var addition = this.role.bossDeathRevitalizePercent;
                var num = addition + param;
                this.role.bossDeathRevitalizePercent = num;
                break;
            }
            case "22": {
                var addition2 = this.role.atkAddition2;
                var num = addition2 + param;
                this.role.atkAddition2 = num;
                break;
            }
        }
        if (data) {
            this.roleAddParamLb(data);
        }
    };
    level_peopleArchery.prototype.getRoleMoveSpd = function () {
        var _a;
        return ((_a = this.role) === null || _a === void 0 ? void 0 : _a.moveSpd) || 0;
    };
    level_peopleArchery.prototype.createOneBox = function (enemy) {
        var pos = enemy.node.getPosition();
        var data = enemy.waveData;
        var box = cc.instantiate(this.boxPrefab);
        var bs = box.getComponent(level_peopleArcheryBox_1.default);
        this.oneUnitBindLevel(bs);
        bs.bindData(enemy.enemyType, data);
        box.setParent(this.unitContent);
        box.setPosition(pos);
    };
    level_peopleArchery.prototype.openBoxPage = function (datas, lastWaveFlag) {
        var _this = this;
        var page = cc.instantiate(this.openBoxPagePrefab);
        var ps = page.getComponent(level_peopleArchery_openBoxPage_1.default);
        var completeFun = lastWaveFlag ? function () { _this.gameWin(); } : null;
        ps.bindData(datas, this, completeFun);
        page.setParent(this.node);
    };
    level_peopleArchery.prototype.openMoneyPage = function (winFlag) {
        if (winFlag === void 0) { winFlag = true; }
        return __awaiter(this, void 0, void 0, function () {
            var page, getMoneyPage;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.PEOPEL_ARCHERY_GET_MONEY_PAGE)];
                    case 1:
                        page = _a.sent();
                        getMoneyPage = page;
                        this.gamePauseFlag = true;
                        getMoneyPage.bindLevel(this, this.curMoney, function () {
                            if (winFlag) {
                                _this.gameWin();
                            }
                            else {
                                _this.gameFail();
                            }
                        });
                        return [2 /*return*/];
                }
            });
        });
    };
    level_peopleArchery.prototype.openRouGePage = function () {
        return __awaiter(this, void 0, void 0, function () {
            var page;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.PEOPLE_ARCHERY_ROUGE)];
                    case 1:
                        page = _a.sent();
                        page.bindLevel(this);
                        return [2 /*return*/];
                }
            });
        });
    };
    /**游戏失败 */
    level_peopleArchery.prototype.gameFail = function () {
        return __awaiter(this, void 0, void 0, function () {
            var page;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.gamePauseFlag = true;
                        return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.LEVEL_PEOPLE_ARCHERY_RESULTPAGE, { mode: this.levelInfo.mode })];
                    case 1:
                        page = _a.sent();
                        page.bindData(this, false);
                        this.destroyOneTypeUnit("bullet");
                        return [2 /*return*/];
                }
            });
        });
    };
    /**游戏胜利 */
    level_peopleArchery.prototype.gameWin = function () {
        return __awaiter(this, void 0, void 0, function () {
            var page;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.gamePauseFlag = true;
                        MainRoot_1.default.LevelSystem.AddLevel(this.m_mode);
                        return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.LEVEL_PEOPLE_ARCHERY_RESULTPAGE, { mode: this.levelInfo.mode })];
                    case 1:
                        page = _a.sent();
                        if (this.infinityFlag && gameEngine_1.default.getManagers().peopleArcheryManager.getData().infinityLevel == gameEngine_1.default.getManagers().peopleArcheryManager.getData().curInfinityLevel && gameEngine_1.default.getManagers().peopleArcheryManager.getData().infinityLevel < Object.keys((gameEngine_1.default.getManagers().csvDataManager.getCsvData(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryInfinityEnemyHp)["title"])).length - 1) {
                            gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().commitRank(gameEngine_1.default.getManagers().peopleArcheryManager.getData().infinityLevel + 1);
                            gameEngine_1.default.getManagers().peopleArcheryManager.setData({ infinityLevel: 1 }, true);
                        }
                        gameEngine_1.default.getManagers().peopleArcheryManager.setData({ curInfinityLevel: 1 }, true);
                        // O1HD.getManagers().peopleArcheryManager.setData({money:this.curMoney},true);
                        page.bindData(this, true);
                        this.destroyOneTypeUnit("bullet");
                        return [2 /*return*/];
                }
            });
        });
    };
    /**角色复活 */
    level_peopleArchery.prototype.peopleAlive = function () {
        this.role.alive();
        this.gamePauseFlag = false;
    };
    level_peopleArchery.prototype.onBtnStart = function (e) {
        this.btnStart.active = false;
        this.gamePauseFlag = false;
    };
    /**
     * 销毁除了角色之外的所有单位
     */
    level_peopleArchery.prototype.destroyAllUnit = function () {
        this.role.node.removeFromParent(false);
        this.unitContent.children.forEach(function (n) {
            var ns = n.getComponent(level_PeopleArcheryUnitBase_1.default);
            ns.unitDestroy();
        });
        this.role.node.setParent(this.unitContent);
    };
    /**
     * 销毁指定类型的所有单位
     * @param type
     */
    level_peopleArchery.prototype.destroyOneTypeUnit = function (type) {
        var c = null;
        switch (type) {
            case "bullet": {
                c = level_peopleArcheryBullet_1.default;
                break;
            }
            case "option": {
                c = level_peopleArcheryOption_1.default;
                break;
            }
            case "enemy": {
                c = level_peopleArcheryEnemy_1.default;
                break;
            }
            case "box": {
                c = level_peopleArcheryBox_1.default;
                break;
            }
        }
        var unitAry = [];
        this.unitContent.children.forEach(function (n) {
            var ns = n.getComponent(c);
            if (ns) {
                unitAry.push(ns);
            }
        });
        for (var _i = 0, unitAry_1 = unitAry; _i < unitAry_1.length; _i++) {
            var k = unitAry_1[_i];
            k.getComponent(c).unitDestroy();
        }
    };
    /**初始化游戏 */
    level_peopleArchery.prototype.initGameData = function () {
        this.killCount = 0;
        this.gameTime = 0;
        this.damage = 0;
        this.waveDis = 0;
        this.realWave = 3;
        this.moveDis = 0;
        this.destroyAllUnit();
    };
    level_peopleArchery.prototype.onDestroy = function () {
        this.bulletPool.clear();
    };
    /** 受伤扣血文本 */
    level_peopleArchery.prototype.addSubLb = function (subNum, targetNode, criticalFlag) {
        if (criticalFlag != null && !criticalFlag) {
            return;
        }
        var node = cc.instantiate(this.subP);
        var baoji = node.getChildByName("baoji");
        baoji.active = criticalFlag != null && criticalFlag;
        var nLb = node.getComponent(cc.Label);
        nLb.string = "-" + subNum;
        node.color = criticalFlag != null && criticalFlag ? cc.Color.RED : cc.color(231, 114, 63);
        node.setParent(this.unitContent);
        node.setPosition(targetNode.position.x, targetNode.position.y + 20);
        cc.tween(node).by(0.5, { y: 50, opacity: 0 }).call(function () {
            node.destroy();
            node.removeFromParent();
        }).start();
    };
    /**角色增加属性文本 */
    level_peopleArchery.prototype.roleAddParamLb = function (data) {
        var targetNode = this.role.node;
        var node = cc.instantiate(this.subP);
        var nLb = node.getComponent(cc.Label);
        nLb.string = gameEngine_1.default.getManagers().peopleArcheryManager.getOptionText(data);
        node.setParent(this.unitContent);
        node.setPosition(targetNode.position.x, targetNode.position.y + 20);
        cc.tween(node).by(0.5, { y: 10, opacity: 0 }).call(function () {
            node.destroy();
            node.removeFromParent();
        }).start();
    };
    /**给角色加一件武器 */
    level_peopleArchery.prototype.roleAddWeapon = function (weaponId) {
        var weaponData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryMagicWeapon, weaponId);
        var param = weaponData["param"];
        var pAry = param.split("&");
        var typeAry = [];
        var paramAry = [];
        pAry.forEach(function (p) {
            var strAry = p.split("|");
            typeAry.push(strAry["0"]);
            paramAry.push(Number(strAry["1"]));
        });
        for (var i = 0; i < typeAry.length; i++) {
            var data = { param_type: typeAry[i], option_param: paramAry[i] };
            this.parseDataAddPeople(data);
        }
        this.role.addOneWeapon(weaponId);
        this.inGamePage.refrenshWeaponContent();
    };
    /**
     * 杀死一个敌方单位
     * @param type 敌方单位类型
     */
    level_peopleArchery.prototype.killOneEnemy = function (type) {
        switch (type) {
            case 0: {
                this.curMoney += Number(this.peopleArcheryData["kill_boss_money"]);
                break;
            }
            case 1: {
                this.curMoney += Number(this.peopleArcheryData["kill_big_money"]);
                break;
            }
            case 2: {
                this.curMoney += Number(this.peopleArcheryData["kill_middle_money"]);
                break;
            }
            case 3: {
                this.curMoney += Number(this.peopleArcheryData["kill_small_money"]);
                break;
            }
        }
        console.log(this.curMoney);
    };
    level_peopleArchery.prototype.openSynthPage = function (weaponId, oneWeaponId, twoWeaponId) {
        return __awaiter(this, void 0, void 0, function () {
            var page, synthPage;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.PEOPLE_ARCHERY_SYNTH_PAGE)];
                    case 1:
                        page = _a.sent();
                        synthPage = page;
                        synthPage.bindLevel(this, weaponId, oneWeaponId, twoWeaponId);
                        return [2 /*return*/];
                }
            });
        });
    };
    __decorate([
        property({ type: cc.Node, tooltip: "单位content" })
    ], level_peopleArchery.prototype, "unitContent", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "角色预制体" })
    ], level_peopleArchery.prototype, "peopleP", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "箭的预制体" })
    ], level_peopleArchery.prototype, "arrowP", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "敌方预制体" })
    ], level_peopleArchery.prototype, "enemyP", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "选项预制体" })
    ], level_peopleArchery.prototype, "optionP", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "箱子预制体" })
    ], level_peopleArchery.prototype, "boxPrefab", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "开箱子预制体" })
    ], level_peopleArchery.prototype, "openBoxPagePrefab", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "结算界面" })
    ], level_peopleArchery.prototype, "resultP", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "开始游戏按钮" })
    ], level_peopleArchery.prototype, "btnStart", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "扣血文本预制体" })
    ], level_peopleArchery.prototype, "subP", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "touch节点" })
    ], level_peopleArchery.prototype, "touchNode", void 0);
    __decorate([
        property({ tooltip: "是否是测试" })
    ], level_peopleArchery.prototype, "testFlag", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "属性文本" })
    ], level_peopleArchery.prototype, "lbParam", void 0);
    level_peopleArchery = __decorate([
        ccclass
    ], level_peopleArchery);
    return level_peopleArchery;
}(LevelBase_1.default));
exports.default = level_peopleArchery;

cc._RF.pop();